/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mail;

import java.math.BigInteger;
import java.security.SecureRandom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author tomasz
 */
@Controller
@RequestMapping("/send.htm")
public class send {
    
    private MailSender mailSender;
    private SimpleMailMessage templateMessage;

    @Autowired
    public void setMailSender(MailSender mailSender) {
        this.mailSender = mailSender;
    }

    @Autowired
    public void setTemplateMessage(SimpleMailMessage templateMessage) {
        this.templateMessage = templateMessage;
    }
    
    
    @RequestMapping(method = RequestMethod.GET)
    public String sendMessage(){
        
        
           SimpleMailMessage msg = new SimpleMailMessage(this.templateMessage);
           msg.setTo("apap001@wp.pl");


           SecureRandom random = new SecureRandom();
           String strhash = new BigInteger(130, random).toString(32);

           msg.setText("Tomek została dodano nowa galeria hash "+strhash);
       
       
        try{

            this.mailSender.send(msg);
            System.out.println("poszlo");
        }
        catch(MailException ex) {
            // simply log it and go on...
            System.out.println(ex.getMessage());
        }
        
        return "index";
        
    }
    
    
}
